home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.1 / Libraries / Intuition / boopsi / classface.asm next >
Encoding:
Assembly Source File  |  1992-08-26  |  4.3 KB  |  167 lines

  1. *  classface.asm - Intuition object/class method invocation
  2. *  converts "standard" C calling conventions to appropriate
  3. *  hook conventions.
  4. *
  5. * Code in here "freezes" these facts (and no others):
  6. *    - pointer to an object's class immediately precedes the object pointer
  7. *    - pointer to a class's superclass is (h_SIZEOF+4) into the class
  8.  
  9.     INCLUDE 'exec/types.i'
  10.     INCLUDE 'exec/nodes.i'
  11.  
  12.     INCLUDE 'utility/hooks.i'
  13.  
  14. * varargs interfaces for invoking method functions
  15.     xdef    _DoMethod
  16.     xdef    _DoSuperMethod
  17.     xdef    _CoerceMethod
  18.     xdef    _SetSuperAttrs
  19.  
  20. * corresponding method invocations for a pre-packaged parameter
  21. * "message" packet
  22.     xdef    _DM
  23.     xdef    _DSM
  24.     xdef    _CM
  25.  
  26. * DoMethod( o, method_id, param1, param2, ... )
  27. * Invoke upon an object the method function defined by an object's class.
  28. * This function (with its "short form" DM() ) is the only one that
  29. * you should use unless you are implementing a class.
  30. *
  31. _DoMethod:
  32.     move.l    a2,-(a7)    ; rely on a6 being preserved
  33.     move.l    8(sp),a2    ; object
  34.     move.l    a2,d0        ; be safe
  35.     beq.s    cmnullreturn
  36.     lea    12(sp),a1    ; message
  37.     move.l    -4(a2),a0    ; object class ptr precedes object
  38.  
  39.     bra.s    cminvoke(pc)    ; will cleanup a2
  40.     ; ----- don't return here
  41.  
  42. * DoSuperMethod( cl, o, method_id, param1, param2, ... )
  43. * Invoke upon an object the method defined for the superclass
  44. * of the class specified.  In a class implementation, you
  45. * are passed a pointer to the class you are implementing, which
  46. * you pass to this function to send a message to the object
  47. * considered as a member of your superclass.
  48. *
  49. _DoSuperMethod:
  50.     move.l    a2,-(a7)    ; rely on a6 being preserved
  51.     movem.l    8(sp),a0/a2    ; class, object
  52.     move.l    a2,d0        ; be safe (object)
  53.     beq.s    cmnullreturn
  54.     move.l    a0,d0        ; be safe (class)
  55.     beq.s    cmnullreturn
  56.     lea    16(sp),a1    ; message
  57.     move.l    h_SIZEOF+4(a0),a0    ; substitute superclass
  58.  
  59.     bra.s    cminvoke(pc)    ; will cleanup a2
  60.     ; ----- don't return here
  61.  
  62. * CoerceMethod( cl, o, method_id, param1, param2, ... );
  63. * Invoke upon the given object a method function for whatever
  64. * specified class.  This is sort of the primitive basis behind
  65. * DoMethod and DoSuperMethod.
  66. *
  67. _CoerceMethod:
  68.     move.l    a2,-(a7)    ; rely on a6 being preserved
  69.     movem.l    8(sp),a0/a2    ; get hook and object
  70.     move.l    a2,d0        ; be safe (object)
  71.     beq.s    cmnullreturn
  72.     move.l    a0,d0        ; be safe (class)
  73.     beq.s    cmnullreturn
  74.     lea    16(sp),a1    ; varargs version
  75.     ; --- registers ready, now call hook
  76.     bra.s    cminvoke(pc)
  77.     ; ----- don't return here
  78.  
  79.  
  80. * CM( a0: cl, a2: o, a1: msg )
  81. * This is CoerceMethod for prepackaged "message" packets
  82. *
  83. _CM:
  84.     move.l    a2,-(a7)    ; rely on a6 being preserved
  85.     movem.l    8(sp),a0/a2    ; get class and object
  86.     move.l    a2,d0
  87.     beq.s    cmnullreturn
  88.     move.l    a0,d0
  89.     beq.s    cmnullreturn
  90.     move.l    16(sp),a1    ; get msg
  91.     ; --- registers ready, now call hook
  92.  
  93.     ; --- performs call to hook in A0 and restores a2
  94. cminvoke:
  95.     pea.l    cmreturn(pc)
  96.     move.l    h_Entry(a0),-(sp)
  97.     rts
  98. cmnullreturn:
  99.     moveq.l    #0,d0
  100. cmreturn:
  101.     move.l    (sp)+,a2
  102.     rts
  103.  
  104.     
  105. * DM( o, msg )
  106. * This is DoMethod for prepackaged "message" packets
  107. _DM:
  108.     move.l    a2,-(a7)    ; rely on a6 being preserved
  109.     move.l    8(sp),a2    ; object
  110.     move.l    a2,d0
  111.     beq.s    cmnullreturn
  112.     move.l    12(sp),a1    ; message
  113.     move.l    -4(a2),a0    ; object class precedes object
  114.  
  115.     bra.s    cminvoke(pc)    ; will cleanup a2
  116.     ; ----- don't return here
  117.  
  118.  
  119. * DSM( cl, o, msg )
  120. * This is DoSuperMethod for prepackaged "message" packets
  121. _DSM:
  122.     move.l    a2,-(a7)    ; rely on a6 being preserved
  123.     movem.l    8(sp),a0/a2    ; class, object
  124.     move.l    a2,d0
  125.     beq.s    cmnullreturn
  126.     move.l    a0,d0
  127.     beq.s    cmnullreturn
  128.     move.l    16(sp),a1    ; message
  129.     move.l    h_SIZEOF+4(a0),a0    ; substitute superclass
  130.  
  131.     bra.s    cminvoke(pc)    ; will cleanup a2
  132.     ; ----- don't return here
  133.  
  134.  
  135. * SetSuperAttrs( cl, o, tag1, data1, ..., TAG_END );
  136. * A useful varargs conversion to the proper OM_SET method.
  137. _SetSuperAttrs:
  138.     move.l    a2,-(a7)    ; save
  139.  
  140.     movem.l    8(sp),a0/a2    ; class, object
  141.     move.l    a2,d0        ; be safe (object)
  142.     beq.s    cmnullreturn
  143.     move.l    a0,d0        ; be safe (class)
  144.     beq.s    cmnullreturn
  145.  
  146.     move.l    h_SIZEOF+4(a0),a0    ; substitute superclass
  147.  
  148.     ; -----    build msg packet on the stack
  149.     move.l    #0,-(sp)    ; NULL GadgetInfo
  150.     pea.l    4+16(sp)    ; address of tags on deeper stack
  151.     move.l    #$103,-(sp)    ; MethodID OM_SET
  152.     lea.l    (sp),a1        ; put the address of the whole thing in a1
  153.  
  154.     pea.l    ssaret(pc)
  155.     move.l    h_Entry(a0),-(sp)
  156.     rts
  157.  
  158. ssaret:
  159.     ; -----    return here to clean up stack
  160.     lea.l    12(sp),sp    ; pop off three long parameters
  161.     move.l    (sp)+,a2    ; pop/restore original a2
  162.     rts
  163.  
  164.  
  165.     end
  166.  
  167.